package cn.wolfcode.vo;

import java.util.List;

/**
 * 封装返回结果
 *
 * @author 杨兴健
 * @Date 2020/7/8 8:26
 */
public class ResultSet<T> {
    public Integer getCurrentPage() {
        return currentPage;
    }

    public ResultSet<T> setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
        return this;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public ResultSet<T> setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public ResultSet<T> setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        return this;
    }

    private Integer currentPage;
    private Integer pageSize;
    private List<T> data;
    private Integer totalCount;


    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ResultSet{");
        sb.append("currentPage=").append(currentPage);
        sb.append(", pageSize=").append(pageSize);
        sb.append(", data=").append(data);
        sb.append(", totalCount=").append(totalCount);
        sb.append('}');
        return sb.toString();
    }

    public List<T> getData() {
        return data;
    }

    public ResultSet<T> setData(List<T> data) {
        this.data = data;
        return this;
    }

    public ResultSet(Integer currentPage, Integer pageSize, Integer totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
    }


    public int getPrevPage() {
        return currentPage - 1 < 1 ? 1 : currentPage - 1;
    }

    public int getNextPage() {
        return currentPage + 1 >= getTotalPage() ? getTotalPage() : currentPage + 1;
    }

    public int getTotalPage() {
        return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
    }
}
